<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/common.css?01_39" />
		<link rel="stylesheet" type="text/css" href="../css/templet.css?01_39" />
		<link rel="stylesheet" type="text/css" href="../fonts/font-awesome.min.css?01_39" />
		<link rel="stylesheet" type="text/css" href="../mui/css/mui.css?01_39" />
		<!--公共js-->
		<script type="text/javascript" src="../common/js/jquery.js?01_39"></script>

		<!--插件-->
		<script type="text/javascript" src="../common/js/vue.min.js?01_39"></script>
		<script type="text/javascript" src="../common/js/mui.min.js?01_39"></script>

		<script type="text/javascript" src="../common/js/fastclick.js?01_39"></script>
		<script type="text/javascript" src="../common/js/common.js?01_39"></script>
		<script type="text/javascript" src="../common/js/main.js?01_39"></script>
		<script type="text/javascript" src="../common/js/app.js?01_39"></script>
		<style>
			.reset_num {
				position: fixed;
				bottom: 0;
				width: 100%;
			}
			
			.reset_num .keyboard .n {
				border-top: 1px solid #e9e9e9;
				border-right: 1px solid #e9e9e9;
				box-sizing: border-box;
			}
			
			.reset_num .close {
				width: 27px;
				height: 27px;
				background-image: url(../images/w/close.png);
				background-size: cover;
				display: inline-block;
			}
		</style>
	</head>

	<body>
		<header class="bg-red9 fff f-20 pad-t-5 pad-b-5 pad-l-10 pad-r-10" style="z-index: 1;">
			<div class="pa back" style="top: 10px;">
				<a onclick="back()"></a>
			</div>
			<div class="center">
				<p class="f-15"><span id="table_name"></span> <span data-l="1271"></span></p>
				<p class="f-10"><span data-l="1070"></span><span class="mag-l-5" id="people_num"></span></p>
			</div>
			<div onclick="cli_change_num()" class="pa regulate fiex" style="top: 5px; right: 0; max-width: 123px; line-height: 1em; min-height: 35px;">
				<span class="fff f-13 pad-r-5 center" data-l="1282"></span>
			</div>
		</header>
		<div id="app" class="wrap_body order_detail confirmed_order" v-cloak>
			<div v-if="clock_v">
				<div class="content pad-t-45">
					<div class="menu">
						<table style="width: 100%; position: fixed;" class="mag-b-45">
							<tbody>
								<tr style="background: #6c5246;">
									<td class="br td1 center fff pad-t-10 pad-b-10">.No</td>
									<td class="td2 br fff pad-t-10 pad-b-10 center">{{b_lg[1356]}}</td>
									<td class="td4 br center fff pad-t-10 pad-b-10">{{b_lg[1278]}}</td>
									<td class="td3 center fff pad-t-10 pad-b-10">{{b_lg[1280]}}</td>
								</tr>
							</tbody>
						</table>
						<div style="height: 42px;"></div>
						<div v-for="(v,k,$index) in shop_table_info.goods_list" class="item">
							<p class="bg-eded c9191 pad-l-12  pad-t-5 pad-b-5">{{b_lg[1272]}}&nbsp;:&nbsp;{{k|ti}}</p>

							<table class="bg-fff" style="width: 100%;">
								<tbody>
									<tr v-for="(v_1,k_1) in v" v-if="v_1.is_package_goods!=1">
										<td class="br td1 center  pad-t-10 pad-b-10">{{v_1.key}}</td>
										<td class="td2 br pad-10">
											<div class="f-20">{{v_1.food_name}}</div>
											<span v-show="v_1.food_spec!=undefined" class="f-12 c999 mag-b-5">[{{v_1.food_spec}}]</span>
											<span v-show="v_1.food_taste!=undefined" class="f-12 c999 mag-b-5">[{{v_1.food_taste}}]</span>
											<div v-for="(v_2,k_2) in v_1.garnish_ids" class="f-12 c999 mag-b-5">{{all_garnish[v_2.garnish_id]}}&nbsp;<span class="fd5749">X{{v_2.count}}</span></div>
											<div class="f-12 c999">
												<span v-if="v_1.is_pack!=0" class="f-12 bg-75cf43 fff  pad-l-2 pad-r-2">{{b_lg[1509]}}</span>
												<span v-if="v_1.is_wait!=0" class="f-12 bg-fd3d3d fff  pad-l-2 pad-r-2">{{b_lg[1511]}}</span>
												<span v-if="v_1.is_give!=0" class="f-12 fff  pad-l-2 pad-r-2" style="background:#0018ff;">{{b_lg[1510]}}</span>
												<span>{{v_1.remarks}}</span>
											</div>
										</td>
										<td class="td4 br center pad-t-10 pad-b-10">{{v_1.count}}</td>
										<td class="td3 center fff pad-t-10 pad-b-10">
											<p class="bg-999 fff  f-12  pad-5 pad-t-3 pad-b-3" style="display: inline-block; width:75%;">{{b_lg[1273]}}</p>
											<p class="mag-t-15 fd5749 f-15">{{v_1.total_price}}</p>
										</td>
									</tr>
									<tr v-else>
										<td class="br td1 center  pad-t-10 pad-b-10">{{$index+1}}</td>
										<td class="td2 br pad-10">
											<div class="f-20">(<span>{{b_lg[1512]}}</span>) {{v_1.food_name}}</div>
											<div v-show="v_1.food_spec!=undefined" class="f-12 c999 mag-b-5">[{{v_1.food_spec}}]</div>
											<dl v-for="(v_3,k_3) in v_1.package_goods_list" style="overflow: hidden;">
												<!--222-->
												<dt class="fr"><span class="c999">{{v_1.package_cate_list[v_3.cate_id].name}}</span></dt>
												<!--<dt class="fr" style="max-width: 30px;"><span class="c999">{{v_1.package_cate_list[v_3.cate_id].name}}</span></dt>-->
												<dd style="overflow: hidden;">
													<div class="fl">{{all_food[v_3.goods_id].goods_name}}</div>
													<span class="fd5749 f-10 fl" v-if="v_3.count!=1"> X{{v_3.count}}</span>
													<!--规格-->
													<span class="fl c999" v-if="v_3.spec_id!=0">[{{all_spec[v_3.spec_id]}}]</span>
													<span class="fl c999" v-if="v_3.taste_id!=0">[{{all_taste[v_3.taste_id]}}]</span>
													<!--配菜-->
													<div class="c999" v-for="(v_4,k_4) in v_3.garnish_ids">{{all_garnish[v_4.garnish_id]}} x{{v_4.count}}</div>
												</dd>

											</dl>
											<div class="clear"></div>
											<div class="f-12 c999">
												<span v-if="v_1.is_pack!=0" class="f-12 bg-75cf43 fff  pad-l-2 pad-r-2">包</span>
												<span v-if="v_1.is_wait!=0" class="f-12 bg-fd3d3d fff  pad-l-2 pad-r-2">待</span>
												<span>{{v_1.remarks}}</span>
											</div>
										</td>
										<td class="td4 br center pad-t-10 pad-b-10">{{v_1.count}}</td>
										<td class="td3 center fff pad-t-10 pad-b-10">
											<p class="bg-999 fff  f-12  pad-5 pad-t-3 pad-b-3" style="display: inline-block; width:75%;">{{b_lg[1273]}}</p>
											<p class="mag-t-15 fd5749 f-15">{{v_1.total_price}}</p>
										</td>
									</tr>

								</tbody>

							</table>
						</div>
					</div>
				</div>

				<div class="bg-fff pad-l-12 pad-r-12 pad-t-15 pad-b-15 result">
					<dl class="cf">
						<dt class="fl">{{b_lg[1278]}}：</dt>
						<dd>{{food_num}}</dd>
					</dl>
					<dl class="cf mag-t-10">
						<dt class="fl">{{b_lg[1279]}}：</dt>
						<dd class="red9 f-b">{{shop_table_info.order_info.tax_service_price}}</dd>
					</dl>
					<dl class="cf mag-t-10">
						<dt class="fl">{{b_lg[1280]}}：</dt>
						<dd class="red9 f-b">{{shop_table_info.order_info.goods_total_price}}</dd>
					</dl>
					<dl class="cf mag-t-10">
						<dt class="fl">{{b_lg[1281]}}：</dt>
						<dd class="red9 f-b">{{shop_table_info.order_info.tax_excise_price}}</dd>
					</dl>
					<dl class="cf mag-t-10">
						<dd class="fr red9 f-20 f-b">{{(parseFloat(shop_table_info.order_info.tax_service_price) + parseFloat(shop_table_info.order_info.goods_total_price) + parseFloat(shop_table_info.order_info.tax_excise_price)).toFixed(1)+'0'}}</dd>
						<dt class="red9 fr mag-t-7">{{b_lg[1277]}}：</dt>
					</dl>
				</div>

				<div class="bg-fff pad-l-12 pad-r-12 pad-t-15 f-13 c666">
					<p><span>{{b_lg[1228]}}：</span><span>{{shop_table_info.order_info.addtime}}</span></p>
					<!--<p><span>订单号：</span><span>04894784</span></p>-->
					<p><span>{{b_lg[1275]}}：</span><span>{{shop_table_info.order_info.user_ser_id_text}}</span></p>
				</div>
				<div class="center bg-fff end pad-t-5 pad-b-18 pad-l-12 pad-r-12 fiex">
					<hr class="fiex1" />
					<div class="mag-l-5 mag-r-5 c999">End</div>
					<hr class="fiex1" />
				</div>
				<div style="height: 50px;"></div>
				<table class="bg-fff pay">
					<tbody>
						<tr>
							<th @click="improve()" style="width: 33.33%;" class="center bg-yellow fff">{{b_lg[1347]}}</th>
							<th @click="console_order()" style="width: 33.33%;background: #999;" class="center fff">{{b_lg[1346]}}</th>
							<th @click="click_print()" style="width: 33.33%;" class="fff center bg-red9">{{b_lg[1313]}}</th>
						</tr>
					</tbody>
				</table>
			</div>
			<!--接口未加载完成界面-->
			<div v-else>
				<div class="mask bg-000 pa loading">
					<div class="pad-l-40 pad-r-40 pad-t-200">
						<div class="bg-fff wrap pr center ">
							<img src="../images/default_graph/animation.gif" />
						</div>
					</div>
				</div>
			</div>
			<transition name="fade">
				<div v-if="key_num==1" @click="close_num" id="table_info_mask" class="mask"></div>
			</transition>
			<transition name="slide-fade">
				<div class="reset_num" v-if="key_num==1" style="z-index: 2;">
					<div class="bg-red9 fff pad-t-5 pad-b-5 pad-l-12 cf f-18 pad-t-12">
						<div class="fl">{{b_lg[1282]}}</div>
						<div @click="close_num()" class="fr pad-l-20  pad-r-12"><span class="close"></span></div>
					</div>
					<div class="pad-l-12 pad-r-12 pad-t-20 f-24 pad-b-20 f-24 bg-fff center">{{peop_num}}</div>
					<!--数字键盘-->
					<div class="keyboard center cf bg-fff">
						<div class="number col-sm-9 f-18">
							<div v-for="(v,k) in list" @touchstart="click_num(k+1)" class="n col-sm-4 pad-t-16 pad-b-16 btn_c">{{v}}</div>
							<div class="n col-sm-4 pad-t-30 pad-b-30"> </div>
							<div @touchstart="click_num(0)" class="n col-sm-4 pad-t-16 pad-b-16 btn_c">0</div>
							<div class="n col-sm-4 pad-t-30 pad-b-30"> </div>
						</div>

						<div class="fun col-sm-3">
							<div @touchstart="del_num" class="n col-sm-12 pad-t-20 pad-b-16 delete btn_c"><span class="del"></span></div>
							<div class="col-sm-12 bg-red9 fff ok">
								<a @touchstart="ok_btn" href="javascript:;" class="bk fff pad-t-80 pad-b-80 btn_c">OK</a>
							</div>
						</div>
					</div>
				</div>
			</transition>
		</div>
		<script>
			var app = null

			function refresh() {
				app.init()
			}

			function cli_change_num() {
				app.change_num()
			}

			function cli_black_btn() {
				app.black_btn();
			}

			function fun1() {
				setlange_obj(); //加载头部语言包
				down_load() //下拉刷新
				var table_id = getQueryString('table'); //读取URL的参数传送的table_id
				var table_zone = getQueryString('table_zone'); //读取URL的参数传送的table_id
				var type = getQueryString("type") //判断是1查看订单 2确认订单
				var all_food = JSON.parse(getItem("all_food")); //所有的菜品
				var all_spec = JSON.parse(getItem("all_spec")); //菜品的所有规格
				var all_garnish = JSON.parse(getItem("all_garnish")); //菜品所有配菜
				var all_taste = JSON.parse(getItem("all_taste")); //菜品的所有口味
				var package_list = JSON.parse(getItem("package_list")); //所有的套餐
				var food_num = 0; //记录菜品总数
				app = new Vue({
					el: '#app',
					data: {
						verification_data: {}, //缓存数据
						verification_memory: "", //缓存需要验证的功能
						verification_el: null, //存储点击的桌子
						verification_state: "0", //验证是否通过
						verification_window: 0, //验证权限窗口
						verification_data: {
							account: "",
							password: "",
							rule_id: ""
						},
						shop_table_info: { //记录餐桌详细数据
							order_info: {
								pax: {}
							}
						},
						order_food: {},
						b_lg: global_lange, //语言包,
						food_num: 0, //菜品数量
						clock_v: false,
						goods_total_price: 0, //总金额
						refuse: "1", //是否显示拒绝订单 1:不显示 2:显示
						ajax_type: "", //ajax状态
						print_order: "1", //1:可以打印 2:不可以打印
						all_garnish: all_garnish,
						list: 9,
						peop_num: "1",
						key_num: "0",
						peop_first: "1",
						key_num: 0,
						all_food: all_food,
						all_spec: all_spec,
						all_garnish: all_garnish,
						all_taste: all_taste,
						package_cate_list: {} //存储套餐分类

					},
					filters: { //Vue过滤时间
						ti: function(value) {
							if(!value) {
								return "00:00";
							}
							var unixTimestamp = new Date(value * 1000);
							return unixTimestamp.format("hh:mm");
						}
					},
					mounted: function() {
						this.verification_memory = JSON.parse(getItem("shop_table_cookbook")).rule_list;
					},
					methods: {
						verification_sub: function() { //提交验证权限
							var username = app.verification_data.account,
								password = app.verification_data.password,
								rule_id = app.verification_data.rule_id;
							common_ajax("1", {
								"username": username,
								"password": password,
								"rule_id": rule_id
							}, "get_cashier_validation", function(e) {
								var star = e.status
								if(star == 1) { //通过
									app.verification_data.account = "";
									app.verification_data.password = "";
									app.verification_state = 1 //同验证
									if(rule_id == 81) {
										app.openTable(app.verification_el)
									} else if(rule_id == 88) {
										app.console_order();

									} else if(rule_id == 89) {
										app.click_print();
									}

									app.verification_window = 0
								} else { //没有通过
									mui.alert(app.b_lg["1499"], app.b_lg["1320"], app.b_lg["1190"], function() {
										//										app.verification_window = 0
									}, "div")
								}

							})

						},
						verification: function(sta, call) { //点击的模块 sta:{81:开单,86:加菜,87换桌,88拒绝,89:用户订单下厨}
							var state = JSON.parse(getItem("shop_table_cookbook")).rule_list;
							console.log("state", state)
							//验证是否需要权限
							yz(sta)

							function yz(a) {
								var ss = 0
								$.each(state, function(k, v) {
									if(v == a) {
										ss = 1
										return false
									} else {
										ss = 0
									}
								});
								if(ss == 1) {
									app.verification_window = 1
									setTimeout(function() {
										document.getElementById("table_open_mask").addEventListener('touchmove', function(e) {
											e.preventDefault()
										}, false)
										document.getElementById("verification").addEventListener('touchmove', function(e) {
											e.preventDefault()
										}, false)
									}, 300)
								} else {
									call()
								}

							}

						},
						verification_whether: function(sta) { //验证是否需要进行账号密码
							var mm = app.verification_memory
							var ss = ""
							$.each(mm, function(k, v) {
								if(sta == v) {
									ss = 1
									return false
								} else {
									ss = 0
								}
							})
							return ss;
						},
						verification_cancle: function() { //权限取消验证
							app.verification_window = 0
							app.verification_data.account = "";
							app.verification_data.password = "";
						},
						init: function() {
							var th = this;
							common_ajax("1", {
								'shop_table_id': table_id,
								'type': 2
							}, "get_shop_table_order_info", function(h) {
								if(h.status != 1) { //判断接口是否调用成功
									mui.toast(h.msg);
									return;
								}
								setItem("get_shop_table_order_info", JSON.stringify(h.result))
								app.shop_table_info = h.result;
								$("#table_name").html(app.shop_table_info.table_name)
								app.people_num = h.result.order_info.pax;
								$("#people_num").html(h.result.order_info.pax)
								if(app.shop_table_info.goods_list.length == 0 || app.shop_table_info.goods_list.length == 'undefined') {
									mui.alert(app.b_lg['1354'], app.b_lg['1320'], "OK", function() {
										app.clock_v = false;
										back()
										return
									})
								}
								$.each(app.shop_table_info.goods_list, function(k, v) { //整理套餐的格式
									$.each(v, function(k2, v2) {
										if(v2.is_package_goods == 1) {
											var obj = {}
											$.each(v2.package_cate_list, function(k3, v3) {
												obj[v3.id] = v3;
											});
											v2.package_cate_list = obj;
										}

									});

								});
								$.each(app.shop_table_info.goods_list, function(k, v) {
									$.each(v, function(k_1, v_1) { //菜品赋上名字
										app.food_num++; //计算出一共有多少道菜
										if(v_1.is_package_goods == 1) {
											app.shop_table_info.goods_list[k][k_1].key = app.food_num;
											app.shop_table_info.goods_list[k][k_1].food_name = package_list[v_1.goods_id].goods_name;
											app.shop_table_info.goods_list[k][k_1].package_goods_list = v_1.package_goods_list;
											app.shop_table_info.goods_list[k][k_1].package_cate_list = v_1.package_cate_list;
											app.shop_table_info.goods_list[k][k_1].is_package_goods = 1;
										} else {
											app.shop_table_info.goods_list[k][k_1].key = app.food_num;
											app.shop_table_info.goods_list[k][k_1].food_name = all_food[v_1.goods_id].goods_name;
											app.shop_table_info.goods_list[k][k_1].food_spec = all_spec[v_1.spec_id];
											app.shop_table_info.goods_list[k][k_1].food_taste = all_taste[v_1.taste_id];
											var i = 0;
											app.shop_table_info.goods_list[k][k_1].garnish_list = [];
											//											$.each(v_1.garnish_ids, function(k_2, v_2) {
											//												app.shop_table_info.goods_list[k][k_1].garnish_list[i] = all_garnish[v_2.garnish_id];
											//												i++;
											//												console.log("app.shop_table_info.goods_list[k][k_1].garnish_list[i]",app.shop_table_info.goods_list[k][k_1].garnish_list[i])
											//											});
										}
									});
								});
								app.clock_v = true;
								common_ajax("1", {
									'shop_table_id': table_id,
									'type': 2
								}, "get_shop_table_order_info", function(h) {
									if(h.result.goods_list.length == 0) {
										app.print_order = 2
									} else {
										app.print_order = 1
									}
								})
							});
						},
						black_btn: function() {
							if(isAPP) {
								var leav = getQueryString("leave");
								//判断是从我的桌台页面打开的还是工作记录页面打开的
								if(leav == 'record') { //工作记录页面打开的
									var preUrl = plus.webview.currentWebview().opener();
									preUrl.evalJS("refresh()");
								} else {
									var preUrl = plus.webview.getWebviewById(getItem("tableStatus.html"));
									preUrl.evalJS('refresh()')
								}
								var ws = plus.webview.currentWebview()
								plus.webview.close(ws.id)
							} else {
								var a = getQueryString("leave")
								if(a == "index") {
									jum("../work/index.html")
								} else if(a == "record") {
									jum("../work/workRecord.html")
								} else if(a == "table") {
									jum("../work/tableStatus.html")
								}

							}
						},
						improve: function() { //改单
							var dat = {}
							var a = getQueryString("leave")
							dat.shop_table_id = table_id
							dat.type = "2"
							jum("order.html?table_id=" + table_id + "&old=1&improve=1&back=con_order&leave=" + a);
						},
						click_print: function() { //确认并下厨

							verify(89, function(e) {
								if(e == 1) {
									click_pri();
								} else {
									mui.alert(app.b_lg["1499"], app.b_lg["1320"], app.b_lg["1190"], function() {}, "div")
								}
							})

							function click_pri() {
								if(app.print_order == 1) {
									var btnArray = [app.b_lg['1049'], app.b_lg['1190']];
									mui.confirm(app.b_lg['1351'], app.b_lg['1190'], btnArray, function(e) {
										if(e.index == 1) {
											common_ajax("1", {
												shop_table_id: table_id,
												language: '0'
											}, "put_order_goods_confirm", function(h) {
												mui.toast(h.msg);
												if(isAPP) {
													var preUrl = plus.webview.currentWebview().opener();
													preUrl.evalJS("refresh(1)");
												}
												com_back();
											});
										}
									}, "div")
								} else {
									mui.toast(app.b_lg['1352'])
								}
							}

						},
						console_order: function() {
							verify(88, function(e) {
								if(e == 1) {
									console_ord();
								} else {
									mui.alert(app.b_lg["1499"], app.b_lg["1320"], app.b_lg["1190"], function() {}, "div")
								}

							})

							function console_ord() {
								var btnArray = [app.b_lg['1049'], app.b_lg['1190']];
								mui.confirm(app.b_lg['1353'], app.b_lg['1320'], btnArray, function(e) {
									if(e.index == 1) {
										common_ajax("1", {
											shop_table_id: table_id
										}, "delete_cart", function(h) {
											if(h.status == 1) {
												mui.alert(app.b_lg['1204'], app.b_lg['1320'], app.b_lg['1190'], function() {
													com_back();
												}, "div")
											} else {
												mui.toast(h.msg)
											}
										})
									}

								}, "div")
							}

						},
						del_num: function() { //删除点餐键盘的数字
							app.peop_num = app.peop_num.substring(0, app.peop_num.length - 1);
							if(!app.peop_num) {
								app.peop_num = "0";
							}
						},
						ok_btn: function() {
							common_ajax("1", {
								shop_table_id: table_id,
								pax: app.peop_num
							}, "set_order_pax", function(h) {
								if(h.status == 1) {
									app.people_num = app.peop_num
									$("#people_num").html(app.people_num)
									app.close_num()
								}
								console.log(h)

							})
						},
						close_num: function() {
							app.key_num = 0
							app.peop_num = 1
							app.peop_first = 1
						},
						change_num: function() {
							app.key_num = 1
						},
						click_num: function(h) { //输入用餐人数
							var regex = /^[0]+/;
							if(app.peop_first != 1) {
								var el = event.currentTarget
								if(app.peop_num == 0 && h == 0) {
									return;
								}
								if(app.peop_num.length >= 4) {
									app.peop_num = "9999"
									return
								}
								app.peop_num = String(app.peop_num + h);
								app.peop_num = app.peop_num.replace(regex, "");
							} else {
								if(h == 1) {
									app.peop_num = "11";
								} else {
									app.peop_num = String(h);
								}

							}
							app.peop_first = 2

						}
					}
				})
				app.init()
			}
		</script>
	</body>

</html>